#ifndef TYPE_H
#define TYPE_H
#include <cstdint>
#include <iostream>
#include <set>
#include <unordered_map>
#include <vector>
namespace tbp {

/**
 * label_in(out) format: (vertex_id,start_time,end_time)
 */
struct Entry {
  uint32_t id_;
  uint32_t start_;
  uint32_t end_;
  Entry() = default;
  Entry(uint32_t i, uint32_t s, uint32_t e) : id_(i), start_(s), end_(e) {}
  friend std::ostream &operator<<(std::ostream &os, const Entry &obj) {
    os << "(" << obj.id_ << "," << obj.start_ << "," << obj.end_ << ")";
    return os;
  }

  // 为了star的优先队列，根据论文描述，endtime最小的在前
  // bool operator<(const Entry &e) const { return this->start_ < e.start_; }
};

/**
 * 主要用于TBP build的返回值，包含Lin和Lout两个label集合
 */
struct Indexes {
  bool handle_in = true;
  std::vector<std::vector<Entry>> label_in_;
  std::vector<std::vector<Entry>> label_out_;
  Indexes() {
    // do nothing
  }
  Indexes(uint32_t num) {
    label_in_.resize(num + 1);
    label_out_.resize(num + 1);
  }
  inline void resize(int num) {
    label_in_.resize(num + 1);
    label_out_.resize(num + 1);
  }
};
using time_pair = std::pair<uint32_t, uint32_t>;

// 单个节点的边的分区情况
struct Vertex_Partition {
  std::vector<uint32_t> map_;            //(第几条边，对应分区)
  std::vector<std::set<uint32_t>> part_; // part_[i]表示第i个分区包含哪些边
  uint32_t part_num = 0;
  std::unordered_map<uint32_t, time_pair> table_;

  inline void resize(int n) { part_.resize(n); }
};

struct Partitions {
  std::vector<Vertex_Partition> vertex_partition_;

  Partitions(int n) { vertex_partition_.resize(n); }
  inline void resize(uint32_t n) { vertex_partition_.resize(n); }
};

} // namespace tbp
#endif